package com.xzw.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcUtils {
    public static int update(String sql) throws Exception {
        String url = ("jdbc:mysql://localhost:3306/xzw?useSSL=false");
        String username = ("root");
        String password = ("root");
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager.getConnection(url, username, password);
            Statement statement = connection.createStatement();
            return statement.executeUpdate(sql);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static void select(String sql) throws Exception {
        String url = ("jdbc:mysql://localhost:3306/xzw?useSSL=false");
        String username = ("root");
        String password = ("root");
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager.getConnection(url, username, password);
            Statement statement = connection.createStatement();
            ResultSet set = statement.executeQuery(sql);
            while (set.next()) {
                String c1 = set.getString(1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
